import cv2
from mediapipe import solutions
import time
cap = cv2.VideoCapture(0)

mpHands = solutions.hands
hands = mpHands.Hands()
mpDraw = solutions.drawing_utils
pTime = 0
count = 0

while True:
    success, fimg = cap.read()
    img = cv2.flip(fimg, 180)
    imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    results = hands.process(imgRGB)

    if results.multi_hand_landmarks:
        for handLms in results.multi_hand_landmarks:
            mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)

    cTime = time.time()
    fps = 1 / (cTime - pTime)
    pTime = cTime
    cv2.putText(img, str(int(fps)), (25, 50), cv2.FONT_HERSHEY_PLAIN, 2, (255, 0, 0), 3)

    cv2.imshow("Image", img)
    #cv2.waitKey(1)
    k = cv2.waitKey(25) & 0xff
    if k == 27:  # 键盘Esc键退出
        break
